﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

using Styx.WoWInternals.DBC;
using Styx.WoWInternals.WoWObjects;
using Styx.WoWInternals;
using Styx.Common;
using Styx.CommonBot.Routines;
using Styx.Helpers;
using Styx.Pathing;
using Styx;
using System.Diagnostics;
using System.Threading;
using System.IO;
using Styx.CommonBot;
using System.Windows.Forms;
using Styx.CommonBot.Inventory;

namespace KingWoW
{
    class BMHunterCombatClass : KingWoWAbstractBaseClass
    {

        private static string Name = "KingWoW BMHunter'";

        #region CONSTANT AND VARIABLES

        //START OF CONSTANTS ==============================
        private string[] StealBuffs = { "Innervate", "Hand of Freedom", "Hand of Protection", "Regrowth", "Rejuvenation", "Lifebloom", "Renew", 
                                      "Hand of Salvation", "Power Infusion", "Power Word: Shield", "Arcane Power", "Hot Streak!",  /*"Avenging Wrath",*/ 
                                      "Elemental Mastery", "Nature's Swiftness", "Divine Plea", "Divine Favor", "Icy Veins", "Ice Barrier", "Holy Shield", 
                                      "Divine Aegis", "Bloodlust", "Time Warp", "Brain Freeze"};
        private const bool LOGGING = true;
        private const bool DEBUG = false;
        private const bool TRACE = false;
        private KingWoWUtility utils = null;
        private Movement movement = null;
        private ExtraUtils extra = null;

        private WoWUnit target = null;
        private WoWUnit tank = null;
        private WoWUnit lastTank = null;
        private bool SoloBotType = false;
        private string BaseBot = "unknown";
        private DateTime nextTimeRuneOfPowerAllowed;
        private TalentManager talents = null;

        private const string DEBUG_LABEL = "DEBUG";
        private const string TRACE_LABEL = "TRACE";
        private const string TANK_CHANGE = "TANK CHANGED";
        private const string FACING = "FACING";

        //START OF SPELLS AND AURAS ==============================
        private const string DRINK = "Drink";
        private const string FOOD = "Food";

        private const string KILLCOMMAND = "Kill Command";
        private const string KILLSHOT = "Kill Shot";
        private const string SERPENTSTING = "Serpent Sting";
        private const string COBRASHOT = "Cobra Shot";
        private const string GLAIVETOSS = "Glaive Toss";
        private const string DIREBEAST = "Dire Beast";
        private const string FOCUSFIRE = "Focus Fire";
        private const string ARCANESHOT = "Arcane Shot";
        private const string MULTISHOT = "Multi-Shot";
        private const string EXPLOSIVE_TRAP = "Explosive Trap";
        private const string BARRAGE = "Barrage";
        private const string RAPIDFIRE = "Rapid Fire";
        private const string STAMPEDE = "Stampede";
        private const string BW = "Bestial Wrath";
        private const string MURDER = "A Murder of Crows";
        

        //START OF MAGE AURAS
        private const string FROSTFIRE_BOLT = "Frostfire Bolt";
        private const string FROST_NOVA = "Frost Nova";
        private const string FIRE_BLAST = "Fire Blast";
        private const string BLINK = "Blink";
        private const string COUNTERSPELL = "Counterspell";
        private const string SUMMON_WATER_ELEMENTAL = "Summon Water Elemental";
        private const string FROSTBOLT = "Frostbolt";
        private const string POLYMORPH = "Polymorph";
        private const string ARCANE_EXPLOSION = "Arcane Explosion";
        private const string ICE_LANCE = "Ice Lance";
        private const string FINGER_OF_FROST = "Fingers of Frost";
        private const string ICE_BLOCK = "Ice Block";
        private const string CONE_OF_COLD = "Cone of Cold";
        private const string REMOVE_CURSE = "Remove Curse";
        private const string SLOW_FALL = "Slow Fall";
        private const string MOLTEN_ARMOR = "Molten Armor";
        private const string ICY_VEINS = "Icy Veins";
        private const string CONJURE_REFRESHMENT = "Conjure Refreshment";
        private const string EVOCATION = "Evocation";
        private const string FLAMESTRIKE = "Flamestrike";
        private const string CONJURE_MANA_GEM = "Conjure Mana Gem";
        private const string MIRROR_IMAGE = "Mirror Image";
        private const string BLIZZARD = "Blizzard";
        private const string FROST_ARMOR = "Frost Armor";
        private const string INVISIBILITY = "Invisibility";
        private const string ARCANE_BRILLANCE = "Arcane Brilliance";
        private const string FROZEN_ORB = "Frozen Orb";
        private const string SPELLSTEAL = "Spellsteal";
        private const string DEEP_FREEZE = "Deep Freeze";
        private const string CONJURE_REFRESHMENT_TABLE = "Conjure Refreshment Table";
        private const string BRAIN_FREEZE = "Brain Freeze";
        private const string MAGE_ARMOR = "Mage Armor";
        private const string TIME_WARP = "Time Warp";
        private const string ALTER_TIME = "Alter Time";

        private const string FREEZE = "Freeze";
        //END OF SPELLS AND AURAS ==============================

        //TALENTS
        private const string PRESENCE_OF_MIND = "Presence of Mind";
        private const string ICE_FLOES = "Ice Floes";
        private const string TEMPORAL_SHIELD = "Temporal Shield";
        private const string BLAZING_SPEED = "Blazing Speed";
        private const string ICE_BARRIER = "Ice Barrier";
        private const string RING_OF_FROST = "Ring of Frost";
        private const string ICE_WARD = "Ice Ward";
        private const string FROSTJAW = "Frostjaw";
        private const string GREATER_INVISIBILITY = "Greater Invisibility";

        private const string COLD_SNAP = "Cold Snap";
        private const string NETHER_TEMPEST = "Nether Tempest";
        private const string LIVING_BOMB = "Living Bomb";
        private const string FROST_BOMB = "Frost Bomb";
        private const string INVOCATION_BUFF = "Invoker's Energy";
        private const string RUNE_OF_POWER = "Rune of Power";
        private const string INCANTER_WARD = "Incanter's Ward";
        //END TALENTS
        //END OF CONSTANTS ==============================

        #endregion

        public BMHunterCombatClass()
        {
            utils = new KingWoWUtility();
            movement = new Movement();
            extra = new ExtraUtils();
            tank = null;
            lastTank = null; ;
            SoloBotType = false;
            BaseBot = "unknown";
            nextTimeRuneOfPowerAllowed = DateTime.Now;
            talents = new TalentManager();

        }

        public override bool Combat
        {
            get
            {
                extra.AnyKeyBindsPressed();
                if (/*ExtraUtilsSettings.Instance.PauseRotation || */ !StyxWoW.IsInGame || !StyxWoW.IsInWorld /*|| utils.IsGlobalCooldown(true)*/ || Me.Silenced || utils.isAuraActive(DRINK) || utils.isAuraActive(FOOD) || Me.IsChanneling || utils.MeIsCastingWithLag())
                    return false;

                tank = utils.SimpleGetTank(40f);
                if (tank == null || !tank.IsValid || !tank.IsAlive) tank = Me;

                if (tank != null && (lastTank == null || lastTank.Guid != tank.Guid))
                {
                    lastTank = tank;
                    utils.LogActivity(TANK_CHANGE, tank.Class.ToString());
                }
                return CombatRotation();
            }
        }

        public override bool Pulse
        {
            get
            {
                extra.AnyKeyBindsPressed();
                if (/*ExtraUtilsSettings.Instance.PauseRotation || */ !StyxWoW.IsInGame || !StyxWoW.IsInWorld || Me.Silenced /*|| utils.IsGlobalCooldown(true)*/ || utils.isAuraActive(DRINK) || utils.isAuraActive(FOOD) || Me.IsChanneling || utils.MeIsCastingWithLag())
                    return false;

                if (!Me.Combat && BMHunterSettings.Instance.UseEvocation)
                    Evocation();
                //UPDATE TANK
                //tank = utils.GetTank();
                tank = utils.SimpleGetTank(40f);
                if (tank == null || !tank.IsValid || !tank.IsAlive) tank = Me;

                if (tank != null && (lastTank == null || lastTank.Guid != tank.Guid))
                {
                    lastTank = tank;
                    utils.LogActivity(TANK_CHANGE, tank.Class.ToString());
                }
                if (tank != null && tank.Combat && !Me.GotTarget)
                    return CombatRotation();
                return false;
            }
        }

        private bool Evocation()
        {
            if (Me.HealthPercent <= BMHunterSettings.Instance.EvocationHP && utils.CanCast(EVOCATION) && !talents.IsSelected(16) && !talents.IsSelected(17))
            {
                utils.LogActivity(EVOCATION);
                return utils.Cast(EVOCATION);
            }
            return false;
        }

        public override bool Pull
        {
            get
            {
                WoWUnit target = Me.CurrentTarget;
                if (target != null && !target.IsFriendly && target.Attackable && !target.IsDead)
                {
                    if (!target.InLineOfSpellSight || !target.InLineOfSight || target.Distance - target.CombatReach - 1 > BMHunterSettings.Instance.PullDistance)
                    {
                        movement.KingHealMove(target.Location, BMHunterSettings.Instance.PullDistance, true, true, target);
                    }
                    if (utils.CanCast(MULTISHOT) /*&& !Me.IsMoving*/)
                    {
                        if (!Me.IsMoving && !Me.IsFacing(target))
                        {
                            utils.LogActivity(FACING, target.Name);
                            Me.SetFacing(target);
                        }

                        utils.LogActivity(MULTISHOT, target.Name);
                        return utils.Cast(MULTISHOT, target);
                    }
                }
                return false;
            }
        }

        public override bool Initialize
        {
            get
            {
                extra.GoStopWatchUpdateKeyBinds();
                if (ExtraUtilsSettings.Instance.SoundsEnabled)
                {
                    try
                    {
                      //  SoundManager.LoadSoundFilePath(@"\Routines\King-wow\Sounds\Welcome.wav");
                      //  SoundManager.SoundPlay();
                    }
                    catch { }
                }
                Logging.Write("Ciao " + Me.Class.ToString());
                Logging.Write("Welcome to " + Name + " custom class");
                Logging.Write("Thanks All HonorBuddy Forum developers for code inspiration!");
                Logging.Write("Powered by Attilio76 and Qi");
                BotEvents.OnBotStart += new BotEvents.OnBotStartDelegate(BotEvents_OnBotStart);
                Lua.Events.AttachEvent("GROUP_ROSTER_UPDATE", UpdateGroupChangeEvent);

                utils.FillParties();
                return true;
            }
        }

        private void UpdateGroupChangeEvent(object sender, LuaEventArgs args)
        {
            Logging.Write("Update Groups composition");
            utils.FillParties();
        }

        void BotEvents_OnBotStart(EventArgs args)
        {
            talents.Update();
            BotUpdate();
        }

        public override bool NeedCombatBuffs { get { return Buff() ; } }

        //public override bool CombatBuffs { get { return Buff(); } }

        public override bool NeedPreCombatBuffs { get { return false; } }

        public override bool NeedPullBuffs { get { return false; } }

        public override bool NeedRest
        {
            get
            {
                if ((utils.isAuraActive(DRINK) || utils.isAuraActive(FOOD)) && (Me.ManaPercent < 100 || Me.HealthPercent < 100))
                    return true;
                if (Me.ManaPercent <= BMHunterSettings.Instance.ManaPercent &&
                !utils.isAuraActive(DRINK) && !Me.Combat && !Me.IsMoving && !utils.MeIsCastingWithLag())
                {
                    WoWItem mydrink = Consumable.GetBestDrink(false);
                    if (mydrink != null)
                    {
                        utils.LogActivity("Drinking/Eating");
                        Styx.CommonBot.Rest.DrinkImmediate();
                        return true;
                    }
                }
                if (Me.HealthPercent <= BMHunterSettings.Instance.HealthPercent &&
                !utils.isAuraActive(FOOD) && !Me.Combat && !Me.IsMoving && !utils.MeIsCastingWithLag())
                {
                    WoWItem myfood = Consumable.GetBestFood(false);
                    if (myfood != null)
                    {
                        utils.LogActivity("Eating");
                        Styx.CommonBot.Rest.DrinkImmediate();
                        return true;
                    }
                }
                return false;
            }
        }

        public void SetNextTimeRuneOfPower()
        {
            //3 seconds wait to avoid popping 2 rune of frost cause has high priority
            nextTimeRuneOfPowerAllowed = DateTime.Now + new TimeSpan(0, 0, 0, 0, 3000);
        }

        
        private bool Buff()
        {
 
            return false;
        }



        private bool Interrupt()
        {
            if (BMHunterSettings.Instance.AutoInterrupt)
            {
                WoWUnit target = null;
                WoWUnit InterruptTargetCandidate = Me.FocusedUnit;
                if (InterruptTargetCandidate == null || InterruptTargetCandidate.IsFriendly || InterruptTargetCandidate.IsDead
                    || !InterruptTargetCandidate.Attackable)
                {
                    if (BMHunterSettings.Instance.TargetTypeSelected == BMHunterSettings.TargetType.MANUAL)
                        target = Me.CurrentTarget;
                    else if (BMHunterSettings.Instance.TargetTypeSelected == BMHunterSettings.TargetType.AUTO)
                    {
                        target = utils.getTargetToAttack(40, tank);
                    }
                    else if (BMHunterSettings.Instance.TargetTypeSelected == BMHunterSettings.TargetType.SEMIAUTO)
                    {
                        target = Me.CurrentTarget;
                        if (target == null || target.IsDead || !target.InLineOfSpellSight || target.Distance - target.CombatReach - 1 > 40)
                            target = utils.getTargetToAttack(40, tank);
                    }
                    InterruptTargetCandidate = target;
                }
                if (InterruptTargetCandidate != null && (InterruptTargetCandidate.IsCasting || InterruptTargetCandidate.IsChanneling)
                    && InterruptTargetCandidate.CanInterruptCurrentSpellCast && utils.CanCast(COUNTERSPELL, InterruptTargetCandidate))
                {
                    utils.LogActivity(COUNTERSPELL, InterruptTargetCandidate.Name);
                    return utils.Cast(COUNTERSPELL, InterruptTargetCandidate);
                }
            }
            return false;
        }

        private bool ProcWork()
        {
            
                WoWUnit target = null;
                if (BMHunterSettings.Instance.TargetTypeSelected == BMHunterSettings.TargetType.MANUAL)
                    target = Me.CurrentTarget;
                else if (BMHunterSettings.Instance.TargetTypeSelected == BMHunterSettings.TargetType.AUTO)
                {
                    target = utils.getTargetToAttack(40, tank);
                }
                else if (BMHunterSettings.Instance.TargetTypeSelected == BMHunterSettings.TargetType.SEMIAUTO)
                {
                    target = Me.CurrentTarget;
                    if (target == null || target.IsDead || !target.InLineOfSpellSight || target.Distance - target.CombatReach - 1 > 40)
                        target = utils.getTargetToAttack(40, tank);
                }
                if (target != null && !target.IsDead && target.InLineOfSpellSight && target.Distance - target.CombatReach - 1 <= 40)
                {
                    
            if (utils.CanCast(MURDER))
            {
                utils.LogActivity(MURDER);
                return utils.Cast(MURDER,target);
            }

            if (utils.CanCast(GLAIVETOSS))
            {
                utils.LogActivity(GLAIVETOSS);
                return utils.Cast(GLAIVETOSS,target);
            }

            if (utils.CanCast(BARRAGE))
            {
                utils.LogActivity(BARRAGE);
                return utils.Cast(BARRAGE,target);
            }

          

            if (utils.CanCast(DIREBEAST))
            {
                utils.LogActivity(DIREBEAST);
                return utils.Cast(DIREBEAST,target);
            }
                }
            
            return false;
        }

       private bool PriorityBuff()
      {   if (utils.CanCast(RAPIDFIRE))
            {
                utils.LogActivity(RAPIDFIRE);
                return utils.Cast(RAPIDFIRE);
             }

              if (utils.CanCast(BW))
            {
                utils.LogActivity(BW);
                return utils.Cast(BW);
            }

              return false;
       }

        private bool BotUpdate()
        {
            if (BaseBot.Equals(BotManager.Current.Name))
                return false;
            if (utils.IsBotBaseInUse("LazyRaider") || utils.IsBotBaseInUse("Tyrael"))
            {
                Logging.Write("Detected LazyRaider/tyrael:");
                Logging.Write("Disable all movements");
                Movement.DisableAllMovement = true;
                SoloBotType = false;
                BaseBot = BotManager.Current.Name;
                return true;
            }

            if (utils.IsBotBaseInUse("Raid Bot"))
            {
                Logging.Write("Detected RaidBot:");
                Logging.Write("Disable all movements");
                Movement.DisableAllMovement = true;
                SoloBotType = false;
                BaseBot = BotManager.Current.Name;
                return true;
            }


            if (utils.IsBotBaseInUse("BGBuddy"))
            {
                Logging.Write("Detected BGBuddy Bot:");
                Logging.Write("Enable PVP Rotation");
                Movement.DisableAllMovement = true;
                SoloBotType = false;
                BaseBot = BotManager.Current.Name;
                return true;
            }

            Logging.Write("Base bot detected: " + BotManager.Current.Name);
            SoloBotType = true;
            BaseBot = BotManager.Current.Name;
            return true;


        }

 
      

         

        private bool CombatRotation()
        {
            if (Me.Combat )
            {
               // WoWUnit target = null;


                if (BMHunterSettings.Instance.TargetTypeSelected == BMHunterSettings.TargetType.MANUAL)
                    target = Me.CurrentTarget;
                else if (BMHunterSettings.Instance.TargetTypeSelected == BMHunterSettings.TargetType.AUTO)
                {
                    target = utils.getTargetToAttack(40, tank);
                }
                else if (BMHunterSettings.Instance.TargetTypeSelected == BMHunterSettings.TargetType.SEMIAUTO)
                {
                    target = Me.CurrentTarget;
                    if (target.IsFriendly || target == null || target.IsDead || !target.InLineOfSpellSight || target.Distance - target.CombatReach - 1 > 40)
                        target = utils.getTargetToAttack(40, tank);
                }

                if (target.IsFriendly || target != null && !target.IsDead && target.InLineOfSpellSight && target.Distance - target.CombatReach - 1 <= 40)
                {
                    if (BMHunterSettings.Instance.TargetTypeSelected == BMHunterSettings.TargetType.AUTO)
                        target.Target();
                    if ((BMHunterSettings.Instance.AutofaceTarget || SoloBotType) && !Me.IsMoving)
                    {
                        Me.SetFacing(target);
                    }
                    #region attack

                    extra.UseAlchemyFlask();
                    extra.UseHealthstone();
                    //extra.UseRacials();
                    // extra.UseTrinket1();
                    //extra.UseTrinket2();
                    extra.UseEngineeringWaist(target);
                    extra.UseEngineeringGloves();

                    if (utils.CanCast(MULTISHOT) && utils.AllAttaccableEnemyMobsInRangeFromTarget(target, 8).Count() > 1 && !Me.Pet.HasAura("Beast Cleave"))
                    {
                        utils.LogActivity(MULTISHOT, target.Name);
                        return utils.Cast(MULTISHOT, target);
                    }

                    if (utils.GetSpellCooldown(EXPLOSIVE_TRAP) == TimeSpan.Zero && !target.HasAura(EXPLOSIVE_TRAP) && utils.AllAttaccableEnemyMobsInRangeFromTarget(target, 8).Count() > 1)
                    {
                        utils.LogActivity(EXPLOSIVE_TRAP);
                        //SpellManager.Cast(EXPLOSIVE_TRAP);
                        utils.Cast(EXPLOSIVE_TRAP, target);
                        return SpellManager.ClickRemoteLocation(target.Location);
                    }



                    if (utils.CanCast(FOCUSFIRE) && Me.GetAllAuras().Any(a => a.Name == "Frenzy" && a.StackCount == 5)) // && !Me.HasAura("The Beast Within"))
                    {
                        utils.LogActivity(FOCUSFIRE);
                        utils.Cast(FOCUSFIRE, Me);
                    }

                    if (utils.CanCast(SERPENTSTING) && !target.HasAura(SERPENTSTING))
                    {
                        utils.LogActivity(SERPENTSTING);
                        return utils.Cast(SERPENTSTING, target);
                    }

                    extra.UseRacials();


                    if (utils.CanCast(BW) && Me.CurrentFocus > 60 && !Me.HasAura("The Beast Within"))
                    {
                        utils.LogActivity(BW);
                        return utils.Cast(BW);
                    }

                    if (utils.CanCast(MULTISHOT) && utils.AllAttaccableEnemyMobsInRangeFromTarget(target, 8).Count() >= 5)
                    {
                        utils.LogActivity(MULTISHOT, target.Name);
                        return utils.Cast(MULTISHOT, target);
                    }


                    if (utils.CanCast(COBRASHOT) && utils.AllAttaccableEnemyMobsInRangeFromTarget(target, 8).Count() >= 5)
                    {
                        utils.LogActivity(COBRASHOT);
                        return utils.Cast(COBRASHOT, target);

                    }

                    if (utils.CanCast(RAPIDFIRE))
                    {
                        utils.LogActivity(RAPIDFIRE);
                        return utils.Cast(RAPIDFIRE);
                    }

                    if (utils.CanCast("Stampede") && Me.HasAura(RAPIDFIRE))
                    {
                        utils.LogActivity("Stampede");
                        return SpellManager.Cast("Stampede");
                    }

                    if (utils.CanCast(KILLSHOT) && Me.CurrentTarget.HealthPercent < 20)
                    {
                        utils.LogActivity(KILLSHOT);
                        return utils.Cast(KILLSHOT, target);
                    }


                    if (utils.CanCast(KILLCOMMAND) && Me.GotAlivePet && Me.Pet.GotTarget && Me.Pet.Location.Distance(Me.Pet.CurrentTarget.Location) < 25)
                    {
                        utils.LogActivity(KILLCOMMAND);
                        return utils.Cast(KILLCOMMAND, target);
                    }

                    if (utils.CanCast(MURDER))
                    {
                        utils.LogActivity(MURDER);
                        return utils.Cast(MURDER, target);
                    }

                    if (utils.CanCast(GLAIVETOSS))
                    {
                        utils.LogActivity(GLAIVETOSS);
                        return utils.Cast(GLAIVETOSS, target);
                    }

                    if (utils.CanCast(DIREBEAST) && Me.CurrentFocus <= 90)
                    {
                        utils.LogActivity(DIREBEAST);
                        return utils.Cast(DIREBEAST, target);
                    }

                    if (utils.CanCast(BARRAGE))
                    {
                        utils.LogActivity(BARRAGE);
                        return utils.Cast(BARRAGE, target);
                    }


                    if (utils.CanCast(ARCANESHOT) && Me.HasAura("Thrill of the Hunt"))
                    {
                        utils.LogActivity(ARCANESHOT);
                        return utils.Cast(ARCANESHOT, target);

                    }


                    if (utils.CanCast(FOCUSFIRE) && Me.GetAllAuras().Any(a => a.Name == "Frenzy" && a.StackCount == 5) && !Me.HasAura(FOCUSFIRE) && !Me.HasAura("The Beast Within")) // && !Me.HasAura("The Beast Within"))
                    {
                        utils.LogActivity(FOCUSFIRE);
                        utils.Cast(FOCUSFIRE, Me);
                    }

                    if (utils.CanCast(ARCANESHOT) && ( Me.CurrentFocus >= 61 || Me.HasAura("The Beast Within")))
                    {
                        utils.LogActivity(ARCANESHOT);
                        return utils.Cast(ARCANESHOT, target);

                    }


                    if (utils.CanCast(COBRASHOT))
                    {
                        utils.LogActivity(COBRASHOT);
                        return utils.Cast(COBRASHOT, target);

                    }

                    // UseCD();
                    // ProcWork();
                    //Multidot();

                    //+++++++++++++++++++++++++AOE rotation end+++++++++++++++++++++++++++++++//
                    //   Multidot();



                }
                    #endregion

                } 
                else if (SoloBotType && Me.CurrentTarget != null && !Me.CurrentTarget.IsDead && (!Me.CurrentTarget.InLineOfSpellSight || !Me.CurrentTarget.InLineOfSight || Me.CurrentTarget.Distance - Me.CurrentTarget.CombatReach - 1 > BMHunterSettings.Instance.PullDistance))
                {
                    movement.KingHealMove(Me.CurrentTarget.Location, BMHunterSettings.Instance.PullDistance, true, true, target);
                }
            

            return false;
    }

        
 
       private bool Multidot()
        {
            if (BMHunterSettings.Instance.MultidotEnabled)
            {
                int enemyNumber = utils.AllAttaccableEnemyMobsInRangeTragettingMyParty(40f, BMHunterSettings.Instance.MultidotAvoidCC).Count();
                if (enemyNumber >= BMHunterSettings.Instance.MultidotEnemyNumberMin)
                {
                    WoWUnit TargetForMultidot = null;
                    //apply  Nether Tempest and always refresh it right before the last tick;
                    if (utils.CanCast(NETHER_TEMPEST) && utils.AllEnemyMobsHasMyAura(NETHER_TEMPEST).Count() < BMHunterSettings.Instance.MultidotEnemyNumberMax)
                    {
                        TargetForMultidot = utils.NextApplyAuraTarget(NETHER_TEMPEST, 40, 1000, BMHunterSettings.Instance.MultidotAvoidCC);
                        if (TargetForMultidot != null)
                        {
                            utils.LogActivity("   MULTIDOT   " + NETHER_TEMPEST, TargetForMultidot.Name);
                            return utils.Cast(NETHER_TEMPEST, TargetForMultidot);
                        }
                    }

                    //apply  Living Bomb and refresh it right before or right after the last tick (the expiring Living Bomb will explode in both cases);
                    if (utils.CanCast(LIVING_BOMB) && utils.AllEnemyMobsHasMyAura(LIVING_BOMB).Count() < 3)
                    {
                        TargetForMultidot = utils.NextApplyAuraTarget(LIVING_BOMB, 40, 1000, BMHunterSettings.Instance.MultidotAvoidCC);
                        if (TargetForMultidot != null)
                        {
                            utils.LogActivity("   MULTIDOT   " + LIVING_BOMB, TargetForMultidot.Name);
                            return utils.Cast(LIVING_BOMB, TargetForMultidot);
                        }
                    }

                }
            }
            return false;
        }
        //Ice veyn
        //Mirror image
        //Alter Time
        private bool UseCD()
        {
            if (Me.Combat && Me.GotTarget)
            {
                if (utils.CanCast(RAPIDFIRE))
                {
                    utils.LogActivity(RAPIDFIRE);
                    return utils.Cast(RAPIDFIRE);
                }
                if (utils.CanCast(BW) && !Me.HasAura(RAPIDFIRE))
                {
                    utils.LogActivity(BW);
                    return utils.Cast(BW);
                }
                if (utils.CanCast("Rabit") && Me.GotAlivePet)
                {
                    utils.LogActivity("Rabit");
                    return utils.Cast("Rabit");
                }

                if (extra.IsTargetBoss())
                {
                    if (utils.CanCast(RAPIDFIRE))
                    {
                        utils.LogActivity(RAPIDFIRE);
                        return utils.Cast(RAPIDFIRE);
                    }
                    if (utils.CanCast(BW) && !Me.HasAura(RAPIDFIRE) )
                    {
                        utils.LogActivity(BW);
                        return utils.Cast(BW);
                    }
                    if (utils.CanCast(STAMPEDE) && Me.HasAura(RAPIDFIRE))
         
                    {
                        utils.LogActivity(STAMPEDE);
                        return utils.Cast(STAMPEDE);
                    }

                    if (utils.CanCast("Readiness") && Me.Pet.HasAura(KILLCOMMAND) &&!utils.CanCast(RAPIDFIRE) && !utils.CanCast(MURDER) && !utils.CanCast(BW) && !utils.CanCast(DIREBEAST))
                    {
                        utils.LogActivity("Readiness");
                        return utils.Cast("Readiness");
                    }
                }
            }
            return false;
        }
    }
}
